﻿<html>

	<head>
		<title>优惠券管理</title>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">

		<link href="../../css/skin/default/style.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" href="../../css/dialog.css">
		<link href="../../js/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />

		<script src="../../js/lib/jquery/jquery-1.10.2.min.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>

		<script src="../../js/lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
		<script src="../../js/lib/jquery.form.js" type="text/javascript"></script>
		<script src="../../js/lib/json2.js" type="text/javascript"></script>
		<script src="../../js/dialog.js"></script>
		<script src="../../js/constants.js" type="text/javascript"></script>
		<script src="../../js/api.js" type="text/javascript"></script>
		<style>
			a:hover {
				cursor: pointer;
			}
		</style>
		<script type="text/javascript">
			var manager;
			$(document).hover(parent.hindMenu);
			var couponUrl = BaseUrl + "Coupon?token=" + $api.getStorage("token");
			var mid = $api.getparastr("mid");

			$(function() {
				toolbar();
				var url = couponUrl+"&key=";
				manager = $("#maingrid4").ligerGrid({
					columns: [ 
						{
							display: '摘要',
							name: 'Fsummary',
							width: 160,
							align: 'left'
						},
						{
							display: '类型',
							name: 'Fctype',
							width: 120, 
							render: function(rowdata, rowindex, value) {
								if(rowdata.Fctype == 1 )
									return "优惠券";
								return "充值劵";
							}
						},
						{
							display: '限领数量(单账户)',
							name: 'Flimitnum',
							width: 160,
							render: function(rowdata, rowindex, value) {
								if(rowdata.Flimitnum == 0 || $api.isEmpty(rowdata.Flimitnum))
									return "不限次数！";
								return "每人限领" + rowdata.Flimitnum + "次";
							}
						},
						{
							display: '描述',
							name: 'Memo',
							minWidth: 300,
							align: 'left',
							render: function(rowdata, rowindex, value) {
								var ret = '';
								if(!$api.isEmpty(rowdata.Fstocknum)) {
									ret = "目标库存:" + rowdata.Fstocknum;
									if(!$api.isEmpty(rowdata.Fcurrnum))
										ret += ";领取数:" + rowdata.Fcurrnum;
									if(!$api.isEmpty(rowdata.Fusenum))
										ret += ";使用数:" + rowdata.Fusenum; 
								}
								if(rowdata.Fctype == 1 ){
									if(rowdata.Fsdtype == 1) {
									var index = rowdata.Fsdate.indexOf("T");
									rowdata.Fsdate = rowdata.Fsdate.substr(0,index);
									index = rowdata.Fedate.indexOf("T");
									rowdata.Fedate = rowdata.Fedate.substr(0,index);
									ret += "消费满￥" + $api.toMoney(rowdata.Ffullvalue) + "时使用,减￥" + $api.toMoney(rowdata.Ffacevalue) + "<br/>" +
										"活动周期:" + rowdata.Fsdate + "至" + rowdata.Fedate;
								}
								if(rowdata.Fsdtype == 2) {
									ret += "消费满￥" + $api.toMoney(rowdata.Ffullvalue) + "时使用,减￥" + $api.toMoney(rowdata.Ffacevalue) + "<br/>" +
										"活动周期:领取后" + rowdata.Fday + "天使用有效";
								}
								}
								else{
									ret += "购买价值￥" + $api.toMoney(rowdata.Ffullvalue)+";可用￥"+ $api.toMoney(rowdata.Ffacevalue) ;
								}
								
								return ret;
							}
						},
						{
							display: '创建时间',
							name: 'Fdate',
							width: 200,
							type: 'date',
								render: function(rowdata, rowindex, value) {
									var data = rowdata.Fdate.replace("T"," ");
									var index = data.indexOf(".");
									return data.substr(0,index);
								}
						}  
					],
					dataAction: 'local',
					url: url,
					width: '100%',
					height:'75%', 
					pageSize: 50,
					rowHeight: '80',
					method: 'get',
					isScroll: true,
					usePager: true,
					onDblClickRow: function(data, rowindex, rowobj) {
					 
						window.location.href = 'Add.html?data=' + escape(JSON.stringify(data));
					}
				});
			});

			function toolbar() {
				$api.getLimit(mid, 0, function(data) {
					$("#icon-list").append(data);
				});
			}

			function doserch() {
				var key = $("#txtKeywords").val();
				 
				var url =  couponUrl+ '&key=' + key;
				manager.GetDataByURL(url);
				
			}

			function f_reload() {
				manager.loadData(true);
			};
 
			function add() {
				window.location.href = 'Add.html';
			}

			function edit() {
				var row = manager.getSelectedRow();
				if(row) { 
					window.location.href = 'Add.html?data=' + escape(JSON.stringify(row));
				} else {
					$.ligerDialog.warn("请选择行");
				}
			}

			function del() {
				var manager = $("#maingrid4").ligerGetGridManager();
				var row = manager.getSelectedRow();

				if(row) {
					if($api.isEmpty(row.Fcurrnum) && row.Fcurrnum > 0) {
						$.ligerDialog.error("该用户劵以被领取,不能删除！");
						return;
					}
					$.ligerDialog.confirm("优惠券删除后不能恢复，\n您确定要移除？", function(yes) {
						if(yes) {
							$api.ajaxapp2(couponUrl+"&action=del",row,function(data){
									f_reload();
							});
						}
					})
				} else {
					$.ligerDialog.warn("请选择行！");
				}
			}

			 
		</script>

	</head>

	<body class="mainbody">
		<form id="form1" onsubmit="return false">
			<div class="toolbar-wrap">
				<div  class="toolbar">
					<div class="l-list">
						<ul id="icon-list" class="icon-list">

						</ul>
					</div>
					<div class="r-list">
						<input type=text ID="txtKeywords" placeholder="名称" class="keyword" />
						<a class='btn-search' href='#' onclick='doserch();'></a>
					</div>
				</div>
			</div>
			<div id="maingrid4" style="margin: 0px;background:#fff;"></div>
			<div class="div-content" style="margin-top: 10px;width:99.5%">
				<div class="divhead">信息管理小贴士</div>
				<hr class="divline" />
				<div style="padding:1px 5px; line-height:22px;"><span style="font-weight:bold">修改：</span>只有对草稿优惠券进行编辑操作。</div>
				<div style="padding:1px 5px; line-height:22px;"><span style="font-weight:bold">删除：</span> 只有草稿优惠券才能删除，如果已经上线优惠出错，则请下线处理；
				</div>
				<div style="padding:1px 5px; line-height:22px;"><span style="color:#FD0036">优惠券一旦上架,则不允许删除，请在上架前检查数据是否完整</span>
				</div>
		</form>

	</body>

</html>